<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ include file="/wesite/view/common/base.jsp" %>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>添加采购计划</title>
    <%@ include file="/wesite/view/common/common.jsp" %>
</head>
<body>
<div class="procurement-plan">
    <div class="box">
        <div class="hd"><h3>采购计划标题</h3></div>
        <div class="con"><input type="text" name="content" placeholder="请输入采购计划标题"></div>
    </div>
    <div class="box">
        <div class="hd"><h3>采购计划标题</h3></div>
        <div class="con"><textarea name="title" placeholder="请输入采购计划说明"></textarea></div>
    </div>
    <div class="box">
        <div class="hd"><h3>封面图片</h3></div>
        <div class="con">
            <div class="upload-pic">
                <div class="hd"><h3>上传图片：</h3></div>
                <div class="content">
                    <div class="pic" id="uheadimg">
                        <input type="hidden" name="filepath">
                        <img src="${webctx }/images/uhead.jpg"/>
                    </div>
                    <span class="upload" id="upheadbtn"></span>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="h88"></div>
<div class="h98"></div>
<div class="procurement-plan-bottom">
    <span onclick="submitBuyplan();">保存并添加商品</span>
</div>
<script src="${webctx}/script/upload.js"></script>
<script src="${webctx}/script/plupload.full.min.js"></script>
<script type="text/javascript">
    var toast = new auiToast({});
    var hotsSubmit = false;
    function submitBuyplan() {
        if (hotsSubmit) {
            return false;
        } else {
            hotsSubmit = true;
        }

        $w.httpRequest({
            url: "${ctx}/we/purchaseTemplate",
            data: {
                "content": $("[name='content']").val(),
                "title": $("[name='title']").val(),
                "url": $("[name='filepath']").val()
            },
            ok: function (ret) {
                window.location.href=ret.Data;
            },
            fail: function () {
                toast().fail({
                    title: "保存失败",
                    duration: 1000
                })
            },
            all: function () {
                hotsSubmit = false;
            }
        })
    }

    var uploader;
    $(function () {
        //setLeftCur("zhugl");
        //lo();
        var plparm = {
            runtimes: 'html5,flash,silverlight,html4',
            browse_button: 'upheadbtn',
            url: '${ctx}/upload/UploadPage@uploadPhoto.page?dir=head&tosave=false',
            flash_swf_url: '${ctx}/plugins/plupload2/Moxie2.swf',
            silverlight_xap_url: '${ctx}/plugins/plupload2/Moxie.xap',
            multi_selection: false,
            filters: {
                max_file_size: '500kb',
                prevent_duplicates: false, //不允许选取重复文件
                mime_types: [{title: "图片文件", extensions: "jpg,png"}] //只允许上传图片文件
            },
            init: {
                FilesAdded: function (up, files) {
                    uploader.start();
                    previewImageOne(files[0], function (imgsrc) {
                        $("#uheadimg img").attr("src", imgsrc);
                    })
                },
                FileUploaded: function (up, file, responseObject) {
                    var re = jQuery.parseJSON(responseObject.response);
                    var photo = re.url.replace(re.basepath, "");
                    $("[name='filepath']").val(photo);
                },
                Error: function (up, err) {
                    if (err.code != "-602") {
                        if (err.code == "-600") {
                            toast.fail({
                                title: "图片大小不能超过500kb",
                                duration: 1000
                            })
                        } else {
                            toast.fail({
                                title: err.code + "-" + err.message,
                                duration: 1000
                            })
                        }
                    }
                    return false;
                }
            }
        };
        $oss.setUpDir("userhead");
        uploader = $oss.initUpload(plparm);
    })
    function previewImageOne(file, callback) {
        if (!file || !/image\//.test(file.type)) return;
        if (file.type == 'image/gif') {
            var fr2 = new mOxie.FileReader();
            fr2.onload = function () {
                callback(fr2.result);
                fr2.destroy();
                fr2 = null;
            }
            fr2.readAsDataURL(file.getSource());
        } else {
            var preloader = new mOxie.Image();
            preloader.onload = function () {
                //preloader.downsize( 300, 300 );
                var imgsrc = preloader.type == 'image/jpeg' ? preloader.getAsDataURL('image/jpeg', 80) : preloader.getAsDataURL(); //得到图片src,实质为一个base64编码的数据
                callback && callback(imgsrc);
                preloader.destroy();
                preloader = null;
            };
            preloader.load(file.getSource());
        }
    }
    /*删除图片*/
    function deleteImg(obj) {
        $(obj).parents('.pic').remove();
    }
</script>
</body>
</html>